package com.mgvlife.ddlw.action;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.mgvlife.ddlw.formbean.ScheduleForm;
import com.mgvlife.ddlw.service.ScheduleService;
import com.mgvlife.ddlw.vo.Result;
import com.mgvlife.ddlw.vo.VoClazz2;
import com.mgvlife.ddlw.vo.VoSchedule;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xinhuo.util.JsonUtil;
import com.xinhuo.vo.JsonEasyUI;

@Controller("scheduleAction")
@Scope("prototype")
public class ScheduleAction extends ActionSupport implements
		ModelDriven<ScheduleForm> {

	private static final long serialVersionUID = -5770736009892702575L;
	private ScheduleForm dataForm = new ScheduleForm();
	@Resource
	private ScheduleService scheduleService = null;

	public void add() {
		Result result = null;
		try {
			result = scheduleService.scheduleAdd(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void update() {
		Result result = null;
		try {
			result = scheduleService.scheduleUpdate(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void list() {
		JsonEasyUI<VoSchedule> result = null;
		try {
			result = scheduleService.getData(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void listByAdmin() {
		JsonEasyUI<VoSchedule> result = null;
		try {
			result = scheduleService.getDataByAdmin(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void getClazzs() {
		JsonEasyUI<VoClazz2> result = null;
		try {
			result = scheduleService.getClazzsData(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void delete() {
		Result result = null;
		try {
			result = scheduleService.scheduleDelete(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	// 开始点到
	public void startDd() {
		Result result = null;
		try {
			result = scheduleService.startDd(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void downLoadExcel() {
		Result result = null;
		try {
			result = scheduleService.downLoadExcel(dataForm);
		} catch (IOException e) {
			e.printStackTrace();
			result = Result.unknownError();
		}
	}

	@Override
	public ScheduleForm getModel() {
		return dataForm;
	}

}
